<template>
	<view class="content">
		<view class="top">
			<view class="box">
				<view class="teamlist">
					<view class="subscription-item empty-box" v-if="myteamlist.length == 0">
						<u-empty mode="list"></u-empty>
					</view>
					<view class="team-item" v-for="item in myteamlist" v-else>
						<view class="avatar">
							<u-avatar :src="item.avatar"
								size="60"></u-avatar>
						</view>
						<view class="text">
							<view class="text-title">
								<view class="text-title-num">
									{{item.nick}}{{item.phone}}
								</view>
								<view class="text-title-lv one" v-if="item.level == 1">
									一级成员
								</view>
								<view class="text-title-lv two" v-else>
									二级成员
								</view>
							</view>
							<view class="text-user">
								 邀请人：{{item.pid_nick}} 
							</view>
							<view class="text-time">
								加入时间：{{item.create_time}}
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { gardMobile } from '@/utils/index.js'
	export default {
		data() {
			return {
				paging: {
					page: 1,
					limit: 10,
				},
				total: null,
				myteamlist: [],
				avatar:'',
				settingData:{}
			}
		},		
		onReachBottom() {
			this.getMyTeam()
		},
		onPullDownRefresh() {
			uni.startPullDownRefresh({
				success: () => this.refresh(),
				complete: () => uni.stopPullDownRefresh()
			})
		},
		onLoad() {
			this.getMyTeam()
			this.settingData = uni.getStorageSync('settingData')
			if(this.settingData){
				this.avatar = this.settingData.image
			}
		},
		methods: {
			getMyTeam(){
				if (this.myteamlist.length == this.total) return
				this.$api.myteam(this.paging).then(res => {
					console.log('myTeamlist',res)
					this.myteamlist = [...this.myteamlist, ...res.data.list]
					this.myteamlist = this.myteamlist.map(item => {
						item.avatar = item.avatar?item.avatar:this.avatar
						return {
							...item,
							phone: gardMobile(item.mobile)
						}
					})
					this.total = res.data.total
					this.paging.page++
				})
			},
			// 刷新列表
			refresh() {
				this.paging.page = 1
				this.total = null
				this.myteamlist = []
				this.getMyTeam()
			},
		}
	}
</script>

<style scoped lang="scss">
	.top {
		padding-top: 20rpx
	}

	.content {
		background: #F5F5F5;
		min-height: 100vh;
		z-index: -1;

		.box {
			padding: 0 30rpx;
		}
	}

	.teamlist {
		padding: 12rpx 20rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
		min-height: 100vh;

		.team-item {
			display: flex;
			padding: 32rpx 0;
			border-bottom: 1rpx solid #dfdfdf;
			justify-content: space-between;
			.avatar {
				display: flex;
				align-items: center;
				padding-right: 20rpx;
			}

			.text {
				flex: 1;
				.text-title {
					display: flex;
					justify-content: space-between;
					.text-title-num {
						font-family: PingFangSC, PingFang SC;
						font-weight: 500;
						font-size: 40rpx;
						color: #111111;
						line-height: 44rpx;
						text-align: left;
						font-style: normal;
					}

					.text-title-lv {
						border-radius: 18rpx;
						font-family: PingFangSC, PingFang SC;
						font-weight: 500;
						font-size: 32rpx;
						font-style: normal;
						padding: 4rpx 10rpx;
					}

					.one {
						background: #FCEED7;
						color: #D06122;
					}

					.two {
						background: #DCE6FC;
						color: #4383DF;
					}
				}

				.text-user {
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 32rpx;
					color: #999999;
					line-height: 34rpx;
					text-align: left;
					font-style: normal;
				}

				.text-time {
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 32rpx;
					color: #999999;
					line-height: 34rpx;
					text-align: left;
					font-style: normal;
				}
			}
		}
	}
</style>